package com.top.ruizhong.app

import android.content.Context
import android.os.Environment
import androidx.camera.camera2.Camera2Config
import androidx.camera.core.CameraXConfig
import androidx.multidex.MultiDex
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.SPStaticUtils
import com.module.lemlin.base.BaseApplication
import com.top.ruizhong.entity.UserInfo
import com.top.ruizhong.entity.UserMe
import com.top.ruizhong.mode.manager.PlayerManager
import rxhttp.RxHttp


class RZApplication : BaseApplication(), CameraXConfig.Provider {

    companion object {
        private const val KEY_HTTP_TOKEN = "token"

        fun userInfoMe(): UserMe? = try {
            GsonUtils.fromJson(SPStaticUtils.getString(USER_INFO_ME), UserMe::class.java)
        } catch (e: Exception) {
            null
        }

        fun setUserInfoMe(userMe: UserMe) {
            SPStaticUtils.put(USER_INFO_ME, GsonUtils.toJson(userMe))
        }
    }

    override fun onCreate() {
        super.onCreate()
        PlayerManager.getDefault().init(INSTANCE, packageName)
        //设置http debug模式
        RxHttp.setDebug(true)
        //设置http公共请求头token
        RxHttp.setOnParamAssembly {
            return@setOnParamAssembly it.addHeader(
                KEY_HTTP_TOKEN, SPStaticUtils.getString(TOKEN)
            )
        }
        //初始dex
        MultiDex.install(INSTANCE)
    }

    override fun getCameraXConfig(): CameraXConfig {
        return Camera2Config.defaultConfig()
    }
}